% str = 'A{title}My A{title2}<title>Here is some text.</title>';
% [i, j] = regexp(text, 'layer\s*{.*hdf5_data_param\s*\{[^\{]*\}*}')
% [i,j] = regexp(str,'A{[^\{]*}')

% [i, j] = regexp(text, 'layer\s*{.*hdf5_data_param\s*{[^\{]*[^\}].*}')

% [i, j] = regexp(text, 'hdf5_data_param\s*{[^\{]*[^\}]}')

text = strtrim(fileread('E:\Academic\X\!FROcclusion\2017-01-15-ResSR\code\caffemodel\VDSR_20_r2.prototxt'));

% [i, j] = regexp(text, 'layer\s*{([^\{]*[^\}])*(hdf5_data_param\s*{[^\{]*[^\}]})\s*(include\s*:\s*{[^\{]*[^\}]})\s*}')

% [i, j] = regexp(text, 'layer\s*\{(s\*\w:\s*\w)*(hdf5_data_param\s*\{[^\{]*\})\s*include:\s*\{[^\{]*\}\s*}')

% [i, j] = regexp(text, 'layer\s*\{.*(hdf5_data_param\s*\{[^\{]*[^\}]\}).*\}')
% layer\s*\{(s\*\w*:\s*\w*)*

% [i, j] = regexp(text, '(hdf5_data_param\s*\{[^\{]*\})\s*include:\s*\{[^\{]*\}')

% [i, j] = regexp(text, 'layer\s*\{((\s*\S*:\s*\S*)*)(\s*hdf5_data_param\s*{[^\{\}]*})((\s*\S*:\s*({[^\{\}]*}))*)\s*}')

head = 'layer\s*\{';
tail = '\s*\}';
p1 = '((\s*\S*\s*:\s*({[^\{\}]*}|\S*))*)';
p2 = '(hdf5_data_param\s*{[^\{\}]*})';

[ii, jj] = regexp(text, [head p1 '\s*' p2 p1 tail]);

for ai = 1 : length(i)
    text(i(ai) : j(ai))
end

%%
x = '{zzz aaa 555';
[i, j] = regexp(x, '([^\{]\w*\s*)')
x(i(1):j(1))
% x(i(2):j(2))

%%
Train.source = 'E:\Academic\X\!FROcclusion\2017-01-15-ResSR\code\caffemodel-Train';
Train.batch_size = 599;
Test.source = 'E:\Academic\X\!FROcclusion\2017-01-15-ResSR\code\caffemodel-Test';
Test.batch_size = 677;

net_file = 'E:\Academic\X\!FROcclusion\2017-01-15-ResSR\code\caffemodel\VDSR_20_r2.prototxt';
mycaffe.net.setFile(net_file, Train, Test)
